$(function(){
    getUserInFo();
    // 退出功能
    $('#logout').click(function(){
        console.log(111)
        layer.confirm('确定退出吗?', {icon: 3, title:'提示'}, function(index){
            alert(1)
            //do something
            localStorage.removeItem('token');
            location.href = '/login.html';
            layer.close(index);
          });
          
          
                 
          
    })




})
function getUserInFo(){
    $.ajax({
        type:'get',
        url:'/my/userinfo',
        //通过headers添加请求头信息
        // headers:{
        //     Authorization:localStorage.getItem('token'||''),
        // },
        success:function(res){
            if (res.status != 0)return layer.msg('错误');
            if (res.data.nickname == ''){
                $('.userinfo .username').html(res.data.username);
            }else{
                $('.userinfo .username').html(res.data.nickname);
            }
            if(res.data.user_pic){
                $('.layui-nav-img').attr('src',res.data.user_pic).show().siblings('.text-avatar').hide();
            }else{
               
                $('.text-avatar').html(res.data.username[0].toUpperCase()).show();
            }
        },
        complete:function(res){
            if (res.responseJSON.status == 1){
                localStorage.removeItem('token');
                location.href = '/login.html';
            }
        }

    })
};